package com.hyh.dao.impl;

import com.hyh.bean.Users;
import com.hyh.dao.DBUtils;
import com.hyh.dao.UsersDao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class UsersDaoImpl extends DBUtils implements UsersDao {


    @Override
    public Users login(String username, String password) {
        Users users = null;
        try {
            String sql = "select * from users where loginName=? and password=?";
            List arrayList = new ArrayList();
            arrayList.add(username);
            arrayList.add(password);
            resultSet = query(sql, arrayList);
            if (resultSet == null){
                return null;
            }
            while(resultSet.next()){
                users = new Users();
                users.setLoginName(username);
                users.setRealName(resultSet.getString("realname"));
                users.setUserId(resultSet.getInt("userid"));
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            closeAll();
        }
        return users;
    }
}
